﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using eBook.Core;
using eBook.Core.BusinessObjects;
using eBook.Core.Contracts;
using eBook.Services.Amazon;

namespace eBook.Services
{
  public class AmazonBookLookup : IBookLookup
  {
    private AmazonSearchEngine _aws = new AmazonSearchEngine();

    public AmazonBookLookup ()
	  {
      // AccessKey        1REKPA0HEES4TPN9ZE02   
      // Secret AccessKey 4pI0a2ZyLXdGI8bOMj7aD/04I2ao9FAF8jpZYMao          
      _aws.SubscriptionId = "1WRF74XYWAF1YEEE1YG2";
      _aws.SearchIndex = SearchIndex.Books;
      _aws.ResponseGroup = new string[] { "ItemAttributes", "Images", "EditorialReview" };    
	  }

    public boBookInfo GetBookInfoByISBN(ISBN isbn)
    {
      if (isbn == null)
        return null;

      boBookInfo info = null;
      _aws.Criteria.Reset();
      _aws.Criteria.ISBN = isbn.StrippedISBN;
      _aws.Search();
      if (_aws.Books.Count != 0)
      {
        info = _aws.Books[0];
        info.InfoProvider = "AWS";
      }
      
      return info;
    }
  }
}
